import 'dart:math';

void main() {
  var t1 = OperatorTest(1, 2);
  var t2 = OperatorTest(3, 4);
  var t3 = t1 + t2;
  print('t3.a=${t3.a} t3.b=${t3.b}');

  var t4 = t1 -t2;
  print('t4.a=${t4.a} t4.b=${t4.b}');

}

class OperatorTest {
  num a, b;

  OperatorTest(this.a, this.b);

  OperatorTest operator +(OperatorTest t) {
    return OperatorTest(a + t.a, b + t.b);
  }

  OperatorTest operator -(OperatorTest t) {
    return OperatorTest(a - t.a, b - t.b);
  }
}

class Television {
  void turnOn() {}
}

class SmartTelevision extends Television {
  @override
  void turnOn() {
    super.turnOn();
  }
}

void _display() {}

class Person {
  final _name;

  Person(this._name);

  String greet(String who) => '你好$who , 我是 $_name';
}

class Impostor implements Person {
  get _name => '';

  @override
  String greet(String who) => '你好$who ,你知道我是谁吗？';
}

String greetBob(Person person) => person.greet('小芸');

class Rectangle {
  num left, top, width, height;

  Rectangle(this.left, this.top, this.width, this.height);

  // 定义两个计算产生的属性
  num get right => left + width;

  set right(num value) => left = value - width;

  num get bottom => top + height;

  set bottom(num value) => top = value - height;
}

void assertTest() {
  var url = 'https://www.baidu.com';
  assert(url.startsWith('http'));
}

class Logger {
  final String name;

  //_cache 该类私有，
  static final Map<String, Logger> _cache = <String, Logger>{};

  factory Logger(String name) {
    return _cache.putIfAbsent(name, () => Logger._internal(name));
  }

  Logger._internal(this.name);
}

class Student {
  num age, size;

  //该类的柱构造函数
  Student(this.age, this.size);

  //委托实现给柱构造函数
  Student.ageConstr(num age) : this(age, 0);

  Student.sizeConstr(num size) : this(12, size);
}

class PointA {
  num x, y;

  PointA(this.x, this.y);

  // 计算两点之间的距离
  num distanceTo(PointA other) {
    var dx = x - other.x;
    var dy = y - other.y;
    return sqrt(dx * dy + dx * dy);
  }
}

class Point {
  num x, y;

  // 使用初始化列表在构造函数执行前设置实例变量
  Point.fromJson(Map<String, num> json)
      : x = json['x'],
        y = json['y'] {
    print('In Point.fromJson():(x:$x,y:$y)');
  }
}

class B {
  int age;
  String name;
}

class A {
  int a = 1;
  double b = 1.0;
  String c = "dd";
  B temp;
}

//class Person {
//  var firstName;
//
//  Person.fromJson(Map data) {
//    print('from person');
//  }
//}
//
//class Employee extends Person {
//  Employee.fromJson(Map data) : super.fromJson(data) {
//    print('from employee');
//  }
//}
